#ifndef GAMEPLAYSCREEN_H
#define GAMEPLAYSCREEN_H

#include "GameLayer.h"

#include "GameCamera.h"

//-------------------------------------------------------
#define LEVEL_PATH_FORMAT "levels/chapter%d_level%d.tmx"
#define COMMON_IMAGE "common.png"
#define COMMON_PLIST "common.plist"
#define BACKGROUND_IMAGE "chap%d.png"
#define BACKGROUND_PLIST "chap%d.plist"

#define Z_LAND 5
#define Z_WATER 7
#define Z_CLOUD 6
#define Z_SPIKE 4
#define Z_ITEM 4
#define Z_DOBJECT 6
#define Z_EFFECT 10
#define Z_HUDLAYER 8


class GameObject;
class Hero;
class HudLayer;

class GamePlayScreen : virtual public GameLayer, virtual public b2ContactListener
{
public:
    GamePlayScreen();
    ~GamePlayScreen();

    virtual void draw();
    virtual void initGameLayer();
    virtual void loadGameLayer();
    virtual void startGame();
    virtual void clearGameLayer();    

    virtual void addStaticObject(GameObject *_staticObject, int _z);
    virtual void addDynamicObject(GameObject *_gameObject, int _z);
    virtual void update(float dt);

    void addToCreateList(GameObject *_gameObj);
    void addToRemoveList(GameObject *_gameObj);
    void removeGameObject(GameObject *_gameObj);
    void destroyBody(b2Body *_physicBody);

    void BeginContact(b2Contact *contact);
    void EndContact(b2Contact *contact);

protected:
    virtual void loadImage();
    virtual void loadMap();
    virtual void loadChatacter() = 0;
    virtual void createMap();
    virtual void createb2World();

public: // properties
    bool isHost;
    float deathLine;
    GAME_STATE gameState;

    GameData *mGameData;
    GameCamera *mCamera;    
    CCTMXTiledMap *tiledMap;
    CCSize worldSize;

    b2World *world;

    CCArray *staticObjects;
    CCArray *dynamicObjects;
    CCArray *landLowestList;
    CCArray *createList;
    CCArray *removeList;

    Hero *mHero;
    CCArray *enemies;
    HudLayer *hudLayer;

    mutex dynamic_objects_mutex, remove_list_mutex, create_list_mutex;
};

#endif // GAMEPLAYSCREEN_H
